package com.gcb.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 工船宝USER账号状态
 */
@Getter
public enum CommonStatusEnum {

    STOP(0, "停用"),
    USE(1, "正常");

    private Integer code;

    private String info;

    CommonStatusEnum(Integer code, String info) {
        this.code = code;
        this.info = info;
    }

    public static String getInfoByCode(Integer code) {
        for (AuthStatusEnum companyAuthStatus : AuthStatusEnum.values()) {
            if (companyAuthStatus.getCode().equals(code)) {
                return companyAuthStatus.getInfo();
            }
        }
        return null;
    }

    public static String getInfo(String type) {
        Integer i = Optional.ofNullable(type)
                .map(Integer::parseInt)
                .orElse(-1);
        return Optional.ofNullable(of(i))
                .map(CommonStatusEnum::getInfo)
                .orElse("");
    }

    public static String getInfo(Integer type) {
        return Optional.ofNullable(of(type))
                .map(CommonStatusEnum::getInfo)
                .orElse("");
    }

    public static CommonStatusEnum of(Integer code) {
        Optional<CommonStatusEnum> first = Arrays.stream(CommonStatusEnum.values()).filter(v -> v.getCode().equals(code)).findFirst();
        return first.orElse(null);
    }

}
